"""
用户评分评论模型定义
"""

from typing import List, Optional
from pydantic import BaseModel, Field
import time


class UserRating(BaseModel):
    """用户评分评论基础模型"""

    user_id: int = Field(..., description="用户ID")
    book_id: int = Field(..., description="图书ID")
    rating: float = Field(..., ge=0.0, le=10.0, description="评分，0-10分")
    comment: Optional[str] = Field(None, description="评论内容")
    created_at: int = Field(
        default_factory=lambda: int(time.time()), description="创建时间戳"
    )
    updated_at: int = Field(
        default_factory=lambda: int(time.time()), description="更新时间戳"
    )


class UserRatingRequest(BaseModel):
    """添加/修改评论请求模型"""

    book_id: int = Field(..., description="图书ID")
    rating: float = Field(..., ge=0.0, le=10.0, description="评分，0-10分")
    comment: Optional[str] = Field(None, description="评论内容")


class UserRatingListResponse(BaseModel):
    """评分评论列表响应模型"""

    message: str = Field(..., description="响应消息")
    ratings_list: List[UserRating] = Field(
        default_factory=list, description="评分评论列表"
    )
    page: int = Field(..., description="当前页码")
    limit: int = Field(..., description="每页数量")
    total: int = Field(..., description="总评论数")
